package movEat.Kernel.Import;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

import movEat.Definitions.Genre;
import movEat.Definitions.MovieDB;
import movEat.Definitions.TVshowDB;

public class Main {
    public static void main(String[] str) throws IOException{
    	List<String> keywords=new LinkedList<String>();
    	keywords.add("professor");
    	keywords.add("birthday-party");
    	
    	//add next line to use database
    	//DataBaseManaging.init("root","root");
    	ImdbParser parser= new ImdbParser();

    	Map<String,MovieDB> movieMap= parser.parseMoviesTable("movies.list.gz");
    	System.out.println("gothere1");
    	List<String> actors=new LinkedList<String>(); 
    	parser.parseActorsTable("actors.list.gz", movieMap,actors,false);
    	System.out.println("gothere2");
    	parser.parseActorsTable("actresses.list.gz", movieMap,actors,true);
    	System.out.println("gothere3");
    	parser.parseStarsTable("ratings.list.gz", movieMap);
    	System.out.println("gothere4");
    	parser.parseCountryTable("countries.list.gz", movieMap);
    	System.out.println("gothere5");
    	parser.parseGenreTable("genres.list.gz", movieMap);
    	System.out.println("gothere6");
    	parser.parseRatingTable("mpaa-ratings-reasons.list.gz", movieMap);
    	System.out.println("gothere7");
    	parser.parseKWTable("keywords.list.gz", movieMap,keywords);
    	System.out.println("gothere8");
    	Map<String,TVshowDB> seriesMap= parser.parseSeriesTable("movies.list.gz");
    	System.out.println("gothere9");
    	parser.parseStarsSeriesTable("ratings.list.gz", seriesMap);

    	
//    	Map<String,MovieDB> movieMap= parser.parseMoviesTable("film_test.txt");
//    	List<String> actors= new LinkedList<String>();
//    	parser.parseActorsTable("actors_test.txt",movieMap,actors,false);
//    	parser.parseActorsTable("actresses_test.txt", movieMap,actors,true);    	
//    	parser.parseStarsTable("stars_test.txt", movieMap);
//    	parser.parseCountryTable("country_test.txt", movieMap);
//    	parser.parseGenreTable("genre_test.txt", movieMap);
//    	parser.parseRatingTable("mpaa_rating_test.txt", movieMap);
//    	parser.parseKWTable("keywords_test.txt", movieMap,keywords);
//    	Map<String,TVshowDB> seriesMap= parser.parseSeriesTable("series_test.txt");

    	//writing actors' list to a file
	   	 File file = new File("write.txt");
	   	 BufferedWriter output = new BufferedWriter(new FileWriter(file));
	   	 for(String actor: actors){
	   		 output.write(actor);
	   		 output.newLine();
	   	 }
	   	 output.close();
    	
    	//the final movie list for Asaf
    	List<MovieDB> movies= new LinkedList<MovieDB>(movieMap.values());

//    	 File file = new File("write.txt");
//    	 BufferedWriter output = new BufferedWriter(new FileWriter(file));
//    	 
//    	for (TVshowDB series: seriesMap.values()){
//    		output.write(series.getImdbName()+"\n");
//    		output.write("\t" + series.getDecade()+"\n");
//    		output.write("\t" + series.getStars()+"\n");
//    	}
// 	   output.close();
//    	
//    	//print everything
//    	for(String actor: actors){
//    		System.out.println(actor);
//    	}
//    	
//    	for (MovieDB movie:movies){
//    		System.out.println(movie.getImdbName());
//    		System.out.println("\t"+movie.getYear());
//    		System.out.println("\t"+movie.getStars());
//    		System.out.println("\t"+movie.getCountry());
//    		if (movie.getGenres()!=null)
//    			for(Genre genre:movie.getGenres()){
//    				System.out.println("\t"+genre.toString());
//    			}
//    		if (movie.getActor_nums()!=null)
//    			for(int n:movie.getActor_nums()){
//    				System.out.println("\t"+actors.get(n));
//    			}
//    		System.out.println("\t"+movie.getRating());
//    		System.out.println("\t"+"isDrink? "+movie.getIsDrink());
//    	}
    	
    	//dynamic test
//    	Scanner scan= new Scanner(System.in);
//		System.out.println("Enter a movie name as appears in Imdb");
//    	while(scan.hasNextLine()){
//    		MovieDB movie=movieMap.get(scan.nextLine());
//    		if (movie==null)
//    			return;
//    		System.out.println(movie.getImdbName());
//    		System.out.println("\t"+movie.getYear());
//    		if (movie.getActors()!=null)
//	    		for(String actor:movie.getActors()){
//	    			System.out.println("\t"+actor);
//	    		}
//    		if (movie.getActor_nums()!=null)
//    			for(int n:movie.getActor_nums()){
//    				System.out.println("\t"+n);
//    			}
//    		System.out.println("\t"+movie.getStars());
//    		System.out.println("\t"+movie.getCountry());
//    		if (movie.getGenres()!=null)
//    			for(Genre genre:movie.getGenres()){
//    				System.out.println("\t"+genre.toString());
//    			}
//    		System.out.println("\t"+movie.getRating());
//    		System.out.println("\t"+"isDrink? "+movie.getIsDrink());
//    	}
    		
    	
    	
    	//static test
//    	List<String> movieList=new LinkedList<String>();
//    	movieList.add("Pretty Woman (1990)");    	
//    	movieList.add("Mona Lisa Smile (2003)");    	
//    	for (String film:movieList){
//    		MovieDB movie=movieMap.get(film);
//    		if (movie==null)
//    			return;
//    		System.out.println(movie.getImdbName());
//    		System.out.println("\t"+movie.getYear());
//    		if (movie.getActors()!=null)
//	    		for(String actor:movie.getActors()){
//	    			System.out.println("\t"+actor);
//	    		}
//    		if (movie.getActor_nums()!=null)
//				for(int n:movie.getActor_nums()){
//					System.out.println("\t"+actors.get(n));
//				}
//    		System.out.println("\t"+movie.getStars());
//    		System.out.println("\t"+movie.getCountry());
//    		if (movie.getGenres()!=null)
//    			for(Genre genre:movie.getGenres()){
//    				System.out.println("\t"+genre.toString());
//    			}
//    		System.out.println("\t"+movie.getRating());
//    		System.out.println("\t"+"isDrink? "+movie.getIsDrink());
//    	}

    }
}
